﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoyoEden.Models;
using CoyoEden;

public partial class User_controls_AlbumSelector : UserControl
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsCallback)
		{
			albumSelector.Albums = AlbumList;
		}
	}

	#region private fields
	private static readonly string ALBUMSCACHEKEY = "AlbumListForMenu";
	private static List<Album> _AlbumList;
	private static object _SyncRoot = new object();
	private static List<Album> AlbumList
	{
		get
		{
			_AlbumList = HttpRuntime.Cache[ALBUMSCACHEKEY] as List<Album>;
			if (_AlbumList == null)
			{
				lock (_SyncRoot)
				{
					if (null == _AlbumList)
					{
						_AlbumList = Album.Albums;
						HttpRuntime.Cache.Insert(ALBUMSCACHEKEY, _AlbumList);
					}
				}
			}
			return _AlbumList;
		}
	}
	#endregion

		#region Album.Saved event subscribing
	static User_controls_AlbumSelector()
	{
		Album.Saved += new EventHandler<SavedEventArgs>(Album_Saved);
	}

	static void Album_Saved(object sender, SavedEventArgs e)
	{
		HttpRuntime.Cache.Remove(ALBUMSCACHEKEY);
	}
	#endregion
}
